﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArmaTuCumpleModel.Model;

namespace ArmaTuCumpleModel.Repository
{
    public class RepFeedBack
    {

        //Referencia a la base de datos
        ArmaTuCumpleDataContext db;


        /*************************
         * Constructor
         * ***********************/

        public RepFeedBack()
        {
            db = new ArmaTuCumpleDataContext();
        }

        /*************************
         * Metodos de Consulta
         * ***********************/

        //Obtiene todos los comentarios de una actividad
        public IQueryable<Feedback> ObtenerFeedBackServicioActividadId(Guid id)
        {
            return from fb in db.Feedbacks
                   where fb.id_servicio_usuario == id
                   select fb;
        }

        /*************************
         * Agregar/Eliminar
         * ***********************/

        //Agrega un FeedBack
        public void AgregarFeedBack(Feedback fb)
        {
            db.Feedbacks.InsertOnSubmit(fb);
        }

        //Elimina un FeedBack
        public void EliminarFeedBack(Feedback fb)
        {
            db.Feedbacks.DeleteOnSubmit(fb);
        }

        /*************************
         * Persistencia
         * ***********************/

        public void Guardar()
        {
            db.SubmitChanges();
        }

        public IQueryable<Feedback> GetAllFeedback()
        {
            return (db.Feedbacks);
        }

        public Feedback GetFeedbackbyId(int id)
        {
            return (db.Feedbacks.SingleOrDefault(u => u.id_feedback == id));
        }
    }
}
